package com.justnow.offer;

import java.util.HashMap;

/**
 * @author justnow
 * Created on 2020-08-18
 * Description
 */
public class Solution6 {
    /**
     * 方法一，迭代方法
     * @param l1
     * @param l2
     * @return
     */
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode head = new ListNode(-1);
        ListNode combine = head;
        while (l1 != null && l2 != null) {
            if (l1.val < l2.val) {
                combine.next = l1;
                l1 = l1.next;
            } else {
                combine.next = l2;
                l2 = l2.next;
            }
            combine = combine.next;
        }

        combine.next = l1 == null ? l2 : l1;

        return head.next;

    }

    /**
     * 方法二，递归的方法
     * @param l1
     * @param l2
     * @return
     */
/*
    public ListNode mergeTwoLists2(ListNode l1, ListNode l2) {

    }
*/

}
class ListNode {
    int val;
    ListNode next;
    public ListNode(int val) {
        this.val = val;
    }
}
